function tm(m){
    var time1=new Date();
    var time2=new Date(m);
    var digit=parseInt((time1.getTime()-time2.getTime())/1000);
    var status="刚刚"
    if(digit<60){
        status="秒前";
        return digit+status;
    }
    else if(digit>=86400){
        status="天前";
        return Math.floor(digit/3600/24)+status;
    }
    else if(digit>=3600){
        status="小时前";
        return Math.floor(digit/3600)+status;
    }
    else if(digit>=60){
        status="分钟前";
        return Math.floor(digit/60)+status;
    }   
}
    var p1=document.querySelector("p");
    p1.innerText= tm("2021-12-20 19:04:02");